Statically-Scoped Exceptions: a Typed Foundation for Aspect-Oriented Error Handling
نویسندگان
چکیده
Aspect-oriented programming systems such as AspectJ provide mechanisms for modularizing crosscutting error-handling concerns. However, AspectJ’s advice does not integrate well with Java’s checked exception mechanism. Furthermore, conventional exception-handling facilities such as AspectJ’s share the problem of accidental exception capture due to the dynamic nature of exception-handling semantics. We propose statically-scoped exceptions as an alternative mechanism for error-handling. In our system, a thrown exception is caught by the nearest lexically-enclosing exception handler, rather than the nearest handler on the call stack. Using static scoping allows us to achieve better modularization, as with AspectJ, and also precudes the problem of exception capture. We provide a static type system that tracks exceptions precisely and ensures that statically-scoped exceptions cannot be misused to cause continuationlike behavior. We hope that our system will serve as a foundation for error handling mechanisms that combine good modularization with strong static reasoning about errors. public class Visitor { public void visitClass(Class o) { try { // method visitor code... } catch (ArchJavaError e) { e.setNode(o); ErrorHandler.print(e); } } public void visitMethod(Method o) { try { // method visitor code... } catch (ArchJavaError e) { e.setNode(o); ErrorHandler.print(e); } } public void visitLiteral(Literal o) { try { // literal visitor code... } catch (ArchJavaError e) { e.setNode(o); ErrorHandler.print(e); } } ... } Figure 1: In this visitor code, taken from the ArchJava compiler, each visit method performs a task such as typechecking on a part of the abstract syntax tree. The visitor code uses exceptions to report typechecking errors; these exceptions must be caught and reported at the end of each visit function before recovering so that typechecking can continue.
منابع مشابه
A Compilation Model for Aspect-Oriented Polymorphically Typed Functional Languages
Introducing aspect orientation to a polymorphically typed functional language strengthens the importance of type-scoped advices; i.e., advices with their effects harnessed by type constraints. As types are typically treated as compile time entities, it is highly desirable to be able to perform static weaving to determine at compile time the chaining of type-scoped advices to their associated jo...
متن کاملType-directed weaving of aspects for polymorphically typed functional languages
Incorporating aspect-oriented paradigm to a polymorphically typed functional language enables the declaration of type-scoped advice, in which the effect of an aspect can be harnessed by introducing possibly polymorphic type constraints to the aspect. The amalgamation of aspect orientation and functional programming enables quick behavioral adaption of functions, clear separation of concerns and...
متن کاملA Compilation Model for Aspect-Oriented Polymorphically Typed Functional Languages (Technical Report)
Introducing aspect orientation to a polymorphically typed functional language strengthens the importance of type-scoped advices; i.e., advices with their effects being harnessed by type constraints. As types are typically treated as compile time entities, it is desirable to be able to perform static weaving to determine at compile time the chaining of type-scoped advices to the invocations of t...
متن کاملModular Concrete Type-inference for Statically Typed Object-oriented Programming Languages ?
The problem of concrete type-inference for statically typed object-oriented programming languages (e.g., Java, C ++) determines at each program point, those objects to which a reference may refer or a pointer may point during execution. We present a new technique called analysis-using-abstract-values which performs modular and demand-driven concrete type-inference of a robust subset of Java wit...
متن کاملOn the Pursuit of Static and Coherent Weaving
Aspect-oriented programming (AOP) has been shown to be a useful model for software development. Special care must be taken when we try to adapt AOP to strongly typed functional languages which come with features like type inference mechanism, polymorphic types, higher-order functions and type-scoped pointcuts. Specifically, it is highly desirable that weaving of aspect-oriented functional progr...
متن کاملذخیره در منابع من
با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید
عنوان ژورنال:
دوره شماره
صفحات -
تاریخ انتشار 2004